package org.example.sword2offer.primary;

/**
 * @author: lynn
 * @Descript: NC25 删除给出链表中的重复元素（链表中元素从小到大有序），使链表中的所有元素都只出现一次
 * @date: 2021/7/7 18:20
 * @version: 1.0
 */
public class Q84_DeleteDuplicatesNode {

    public static void main(String[] args) {
        ListNode listNode=new ListNode(0);
        listNode.next=new ListNode(1);
        listNode.next.next=new ListNode(1);
        listNode.next.next.next=new ListNode(2);
        listNode.next.next.next.next=new ListNode(3);
        Q84_DeleteDuplicatesNode deleteDuplicatesNode=new Q84_DeleteDuplicatesNode();
        deleteDuplicatesNode.deleteDuplicates(listNode);
        System.out.println("xxxxxx");
    }
    public ListNode deleteDuplicates (ListNode head) {
        // write code here
        if(head==null) return head;
        ListNode tmp=head;
        while(tmp.next!=null){
            if(tmp.next.val==tmp.val){
                tmp.next=tmp.next.next;
            }else{
                //否则就继续往下走
                tmp=tmp.next;
            }
        }
        //fixme 为什么不返回 tmp,因为你这个时候tmp已经到最后了啊
        return head;
    }

    public static class ListNode{
        ListNode next;
        int val;
        ListNode(int val){
            this.val=val;
        }
    }
}
